#include "..\include\CCard.h"

/*****************************************************************************/
/**                                 class CCard                             **/
/*****************************************************************************/

CCard::ValueType CharToCardValue(char chValue)
{
    switch (chValue)
    {
        case '2': return CCard::vTwo;
        case '3': return CCard::vThree;
        case '4': return CCard::vFour;
        case '5': return CCard::vFive;
        case '6': return CCard::vSix;
        case '7': return CCard::vSeven;
        case '8': return CCard::vEight;
        case '9': return CCard::vNine;
        case 'T': return CCard::vTen;
        case 'J': return CCard::vJack;
        case 'Q': return CCard::vQueen;
        case 'K': return CCard::vKing;
        case 'A': return CCard::vAce;
    };
    throw string("Wrong value");
}

char CardValueToChar(CCard::ValueType cardValue)
{
    switch ( cardValue )
    {
        case CCard::vTwo:   return '2';
        case CCard::vThree: return '3';
        case CCard::vFour:  return '4';
        case CCard::vFive:  return '5';
        case CCard::vSix:   return '6';
        case CCard::vSeven: return '7';
        case CCard::vEight: return '8';
        case CCard::vNine:  return '9';
        case CCard::vTen:   return 'T';
        case CCard::vJack:  return 'J';
        case CCard::vQueen: return 'Q';
        case CCard::vKing:  return 'K';
        case CCard::vAce:   return 'A';
    }
    throw string("Wrong value");
}

CCard::SuitType CharToSuitType(char chSuit)
{
    switch (chSuit)
    {
        case 'H': return CCard::sHearts;
        case 'D': return CCard::sDiamonds;
        case 'C': return CCard::sClubs;
        case 'S': return CCard::sSpades;
    };
    throw string("Wrong suite");
}

char CardSuitToChar(CCard::SuitType cardSuit)
{
    switch ( cardSuit )
    {
        case CCard::sHearts:   return 'H';
        case CCard::sDiamonds: return 'D';
        case CCard::sClubs:    return 'C';
        case CCard::sSpades:   return 'S';
    }
    throw string("Wrong suit");
}

CCard::CCard(const string& shortcut)
{
    mSuit  = CharToSuitType(shortcut[1]);
    mValue = CharToCardValue(shortcut[0]);
}

ostream& operator << (ostream& ostr, const CCard& card)
{
    ostr << CardValueToChar(card.getValue()) << CardSuitToChar(card.getSuit());
    return ostr;
}
